'use strict';
//发布评论
const db = uniCloud.database();
const uniID = require('uni-id')
const dbCmd = db.command
exports.main = async (event, context) => {
	//event为客户端上传的参数
	
	const uniIDIns = uniID.createInstance({
	  context
	})
	let payload={}
	payload = await uniIDIns.checkToken(event.uniIdToken)
	if (payload.code && payload.code > 0) {
		return payload
	}
	event.user_id = payload.uid;
	console.log('event : ', event)
	const collection = db.collection('comment')
	const res=await collection.add(event)
	let memory = await db.collection('memory').where({
		_id:event.memoryId
	}).update({
		commentTotal:dbCmd.inc(1)
	})
	console.log(memory,'xxxxxxxxxx',res,'rrrrrrrrrrrr')
	//返回数据给客户端
	return {res:res,mem:memory}
};
